version 14.1
set more off

***************************************************************************************************
*THIS FILE PRODUCES TABLE A.XVI OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************

*--------------------------
* MAIN REGRESSION 
*--------------------------

/* COLUMN 1 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d				cr
g				treat=namefreq_baseline<=10
drop			if namefreq_baseline>10 & namefreq_baseline<=40
local			j=1
keep			regno year treat
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2012
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local			j=`j'+1

/* COLUMN 2 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
g				treat=namefreq_baseline<=20
drop			if namefreq_baseline>20 & namefreq_baseline<=40
keep			regno year treat
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2012
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local			j=`j'+1

/* COLUMN 3 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
g				treat=namefreq_baseline<=30
drop			if namefreq_baseline>30 & namefreq_baseline<=40
keep			regno year treat
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2012
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local			j=`j'+1

/* COLUMN 4 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
g				treat=namefreq_baseline<=40
keep			regno year treat
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2012
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local			j=`j'+1

/* COLUMN 5 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
qui				sum namefreq_baseline if year<2012,d
g				treat=namefreq_baseline<=r(p50)
keep			regno year treat
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2012
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local			j=`j'+1

/* COLUMN 6 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
qui             sum namefreq_baseline if year<2012, d
g               treat=namefreq_baseline<=r(p25)
drop            if namefreq_baseline>r(p25) & namefreq_baseline<=r(p75)
keep			regno year treat
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2012
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local			j=`j'+1

/* COLUMN 7 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
qui             sum namefreq_baseline if year<2012, d
g               treat=namefreq_baseline<=r(p10)
drop            if namefreq_baseline>r(p10) & namefreq_baseline<=r(p90)
keep			regno year treat
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2012
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]

*--------------------------
* PLACEBO REGRESSION 
*--------------------------

/* COLUMN 1 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
g				treat=namefreq_baseline<=10
drop			if namefreq_baseline>10 & namefreq_baseline<=40
local			j=1
keep			regno year treat
keep			if year<=2011
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2010
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local			j=`j'+1

/* COLUMN 2 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
g				treat=namefreq_baseline<=20
drop			if namefreq_baseline>20 & namefreq_baseline<=40
keep			regno year treat
keep			if year<=2011
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2010
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local			j=`j'+1

/* COLUMN 3 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
g				treat=namefreq_baseline<=30
drop			if namefreq_baseline>30 & namefreq_baseline<=40
keep			regno year treat
keep			if year<=2011
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2010
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local			j=`j'+1

/* COLUMN 4 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
g				treat=namefreq_baseline<=40
keep			regno year treat
keep			if year<=2011
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2010
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local			j=`j'+1

/* COLUMN 5 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
qui				sum namefreq_baseline if year<2012,d
g				treat=namefreq_baseline<=r(p50)
keep			regno year treat
keep			if year<=2011
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2010
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local			j=`j'+1

/* COLUMN 6 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
qui             sum namefreq_baseline if year<2012, d
g               treat=namefreq_baseline<=r(p25)
drop            if namefreq_baseline>r(p25) & namefreq_baseline<=r(p75)
keep			regno year treat
keep			if year<=2011
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2010
g				treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local			i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local			j=`j'+1

/* COLUMN 7 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_BaselineNameFreq.dta", clear
qui             sum namefreq_baseline if year<2012, d
g               treat=namefreq_baseline<=r(p10)
drop            if namefreq_baseline>r(p10) & namefreq_baseline<=r(p90)
keep			regno year treat
keep			if year<=2011
g				one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g				lnfilers=log(nfilers)
g				nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g				after=year>=2010
g				treat_after=treat*after
				reg nfnormalized i.year treat treat_after
local			i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]

/* FORMATTING THE TABLE */ 

svmat 			table
keep			tab*
drop			table8-table12
keep			if _n<=4
g				c11=""
replace			c11="treat $\times$ after" in 1
replace			c11="treat $\times$ after" in 3
forvalues 		c=1/7 {
g				c`c'=string(table`c',"%9.3f")
}
foreach			r in 2 4 {
forvalues		c=1/7 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		s=1/10 {
g				s`s'="&"
}
g				l="\\"
foreach			r in 2 4 {
replace			l="\\\\" in `r'
}
order			c11 s1 c1 s2 c2 s3 c3 s4 c4 s5 c5 s6 c6 s7 c7 l
browse			c11 s1 c1 s2 c2 s3 c3 s4 c4 s5 c5 s6 c6 s7 c7 l
